/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package logic;

import entityBeans.Acceptednameusage;
import entityBeans.Associatedsequence;
import entityBeans.Basisofrecord;
import entityBeans.Behavior;
import entityBeans.Class;
import entityBeans.Collectioncode;
import entityBeans.Continent;
import entityBeans.Country;
import entityBeans.County;
import entityBeans.Dataset;
import entityBeans.Disposition;
import entityBeans.Dynamicproperty;
import entityBeans.Establishmentmean;
import entityBeans.Family;
import entityBeans.Genus;
import entityBeans.Georeferencedby;
import entityBeans.Georeferencesource;
import entityBeans.Georeferenceverificationstatus;
import entityBeans.Habitat;
import entityBeans.Identificationqualifier;
import entityBeans.Identifiedby;
import entityBeans.Individual;
import entityBeans.Infraspecificepithet;
import entityBeans.Institutioncode;
import entityBeans.Island;
import entityBeans.Islandgroup;
import entityBeans.Kingdom;
import entityBeans.Lifestage;
import entityBeans.Locality;
import entityBeans.Municipality;
import entityBeans.Nameaccordingto;
import entityBeans.Namepublishedin;
import entityBeans.Nomenclaturalcode;
import entityBeans.Order1;
import entityBeans.Originalnameusage;
import entityBeans.Ownerinstitution;
import entityBeans.Parentnameusage;
import entityBeans.Phylum;
import entityBeans.Preparation;
import entityBeans.Recordedby;
import entityBeans.Reproductivecondition;
import entityBeans.Samplingprotocol;
import entityBeans.Scientificname;
import entityBeans.Scientificnameauthorship;
import entityBeans.Sex;
import entityBeans.Specificepithet;
import entityBeans.Stateprovince;
import entityBeans.Subgenus;
import entityBeans.Taxonconcept;
import entityBeans.Taxonomicstatus;
import entityBeans.Taxonrank;
import entityBeans.Type;
import entityBeans.Typestatus;
import entityBeans.Waterbody;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import persistence.AcceptednameusageJpaController;
import persistence.AssociatedsequenceJpaController;
import persistence.BehaviorJpaController;
import persistence.ClassJpaController;
import persistence.CollectioncodeJpaController;
import persistence.ContinentJpaController;
import persistence.CountryJpaController;
import persistence.CountyJpaController;
import persistence.DatasetJpaController;
import persistence.DispositionJpaController;
import persistence.DynamicpropertyJpaController;
import persistence.EstablishmentmeanJpaController;
import persistence.FamilyJpaController;
import persistence.GenusJpaController;
import persistence.GeoreferencedbyJpaController;
import persistence.GeoreferencesourceJpaController;
import persistence.GeoreferenceverificationstatusJpaController;
import persistence.HabitatJpaController;
import persistence.IdentificationqualifierJpaController;
import persistence.IdentifiedbyJpaController;
import persistence.IndividualJpaController;
import persistence.InfraspecificepithetJpaController;
import persistence.InstitutioncodeJpaController;
import persistence.IslandJpaController;
import persistence.IslandgroupJpaController;
import persistence.KingdomJpaController;
import persistence.LifestageJpaController;
import persistence.LocalityJpaController;
import persistence.MunicipalityJpaController;
import persistence.NameaccordingtoJpaController;
import persistence.NamepublishedinJpaController;
import persistence.NomenclaturalcodeJpaController;
import persistence.Order1JpaController;
import persistence.OriginalnameusageJpaController;
import persistence.OwnerinstitutionJpaController;
import persistence.ParentnameusageJpaController;
import persistence.PhylumJpaController;
import persistence.PreparationJpaController;
import persistence.RecordedbyJpaController;
import persistence.ReproductiveconditionJpaController;
import persistence.SamplingprotocolJpaController;
import persistence.ScientificnameJpaController;
import persistence.ScientificnameauthorshipJpaController;
import persistence.SexJpaController;
import persistence.SpecificepithetJpaController;
import persistence.StateprovinceJpaController;
import persistence.SubgenusJpaController;
import persistence.TaxonconceptJpaController;
import persistence.TaxonomicstatusJpaController;
import persistence.TaxonrankJpaController;
import persistence.TypeJpaController;
import persistence.TypestatusJpaController;
import persistence.WaterbodyJpaController;

/**
 *
 * @author joao
 */
public class SaveTables {
    
    Connection conn;

    public SaveTables (Connection conn){
        this.conn = conn;
    }


    public List<Institutioncode> saveInstitutioncode(List<Institutioncode> oldList) throws SQLException {
        List<Institutioncode> newList = new ArrayList<Institutioncode>();
        Institutioncode aux = new Institutioncode();
        StringBuilder sql = new StringBuilder("select * from institutioncode where");
        for (Institutioncode i : oldList) {
            sql.append(" institutioncode=E'").append(i.getInstitutioncode()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Institutioncode(); //precisa?
            aux.setInstitutioncode(resultset.getString("institutioncode"));
            aux.setIdinstitutioncode(resultset.getInt("idinstitutioncode"));
            newList.add(aux);
        }

        for (Institutioncode i : oldList) {
            boolean exist = false;
            for (Institutioncode j : newList) {
                if (i.getInstitutioncode().equals(j.getInstitutioncode())) {
                    exist = true;
                    break; //colocar nos outros
                }
            }
            if (!exist) {
                InstitutioncodeJpaController jpaCont = new InstitutioncodeJpaController();
                i.setInstitutioncode(i.getInstitutioncode().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Basisofrecord> saveBasisofrecord(List<Basisofrecord> oldList) throws SQLException {
        List<Basisofrecord> newList = new ArrayList<Basisofrecord>();
        Basisofrecord aux = new Basisofrecord();
        StringBuilder sql = new StringBuilder("select * from Basisofrecord where");
        for (Basisofrecord i : oldList) {
            sql.append(" Basisofrecord=E'").append(i.getBasisofrecord()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Basisofrecord(); //precisa?
            aux.setBasisofrecord(resultset.getString("Basisofrecord"));
            aux.setIdbasisofrecord(resultset.getInt("idBasisofrecord"));
            newList.add(aux);
        }

        for (Basisofrecord i : oldList) {
            boolean exist = false;
            for (Basisofrecord j : newList) {
                if (i.getBasisofrecord().equals(j.getBasisofrecord())) {
                    exist = true;
                }
            }
            if (!exist) {
                System.out.println("SSS ERROR: NAO EXISTE BASIS OF RECORD");
            }
        }
        return newList;
    }

    public List<Collectioncode> saveCollectioncode(List<Collectioncode> oldList) throws SQLException {
        List<Collectioncode> newList = new ArrayList<Collectioncode>();
        Collectioncode aux = new Collectioncode();
        StringBuilder sql = new StringBuilder("select * from collectioncode where");
        for (Collectioncode i : oldList) {
            sql.append(" collectioncode=E'").append(i.getCollectioncode()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Collectioncode(); //precisa?
            aux.setCollectioncode(resultset.getString("collectioncode"));
            aux.setIdcollectioncode(resultset.getInt("idcollectioncode"));
            newList.add(aux);
        }

        for (Collectioncode i : oldList) {
            boolean exist = false;
            for (Collectioncode j : newList) {
                if (i.getCollectioncode().equals(j.getCollectioncode())) {
                    exist = true;
                }
            }
            if (!exist) {
                CollectioncodeJpaController jpaCont = new CollectioncodeJpaController();
                i.setCollectioncode(i.getCollectioncode().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Ownerinstitution> saveOwnerinstitution(List<Ownerinstitution> oldList) throws SQLException {
        List<Ownerinstitution> newList = new ArrayList<Ownerinstitution>();
        Ownerinstitution aux = new Ownerinstitution();
        StringBuilder sql = new StringBuilder("select * from ownerinstitution where");
        for (Ownerinstitution i : oldList) {
            sql.append(" ownerinstitution=E'").append(i.getOwnerinstitution()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Ownerinstitution(); //precisa?
            aux.setOwnerinstitution(resultset.getString("ownerinstitution"));
            aux.setIdownerinstitution(resultset.getInt("idownerinstitution"));
            newList.add(aux);
        }

        for (Ownerinstitution i : oldList) {
            boolean exist = false;
            for (Ownerinstitution j : newList) {
                if (i.getOwnerinstitution().equals(j.getOwnerinstitution())) {
                    exist = true;
                }
            }
            if (!exist) {
                OwnerinstitutionJpaController jpaCont = new OwnerinstitutionJpaController();
                i.setOwnerinstitution(i.getOwnerinstitution().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        for (Ownerinstitution i : newList) {
        System.out.println("A"+i.getIdownerinstitution()+"A");
        }
        return newList;
    }

    public List<Dataset> saveDataset(List<Dataset> oldList) throws SQLException {
        List<Dataset> newList = new ArrayList<Dataset>();
        Dataset aux = new Dataset();
        StringBuilder sql = new StringBuilder("select * from dataset where");
        for (Dataset i : oldList) {
            sql.append(" dataset=E'").append(i.getDataset()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Dataset(); //precisa?
            aux.setDataset(resultset.getString("Dataset"));
            aux.setIddataset(resultset.getInt("idDataset"));
            newList.add(aux);
        }

        for (Dataset i : oldList) {
            boolean exist = false;
            for (Dataset j : newList) {
                if (i.getDataset().equals(j.getDataset())) {
                    exist = true;
                }
            }
            if (!exist) {
                DatasetJpaController jpaCont = new DatasetJpaController();
                i.setDataset(i.getDataset().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Type> saveType(List<Type> oldList) throws SQLException {
        List<Type> newList = new ArrayList<Type>();
        Type aux = new Type();
        StringBuilder sql = new StringBuilder("select * from Type where");
        for (Type i : oldList) {
            sql.append(" Type=E'").append(i.getType()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Type(); //precisa?
            aux.setType(resultset.getString("Type"));
            aux.setIdtype(resultset.getInt("idType"));
            newList.add(aux);
        }

        for (Type i : oldList) {
            boolean exist = false;
            for (Type j : newList) {
                if (i.getType().equals(j.getType())) {
                    exist = true;
                }
            }
            if (!exist) {
                TypeJpaController jpaCont = new TypeJpaController();
                i.setType(i.getType().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Behavior> saveBehavior(List<Behavior> oldList) throws SQLException {
        List<Behavior> newList = new ArrayList<Behavior>();
        Behavior aux = new Behavior();
        StringBuilder sql = new StringBuilder("select * from behavior where");
        for (Behavior i : oldList) {
            sql.append(" behavior=E'").append(i.getBehavior()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Behavior(); //precisa?
            aux.setBehavior(resultset.getString("Behavior"));
            aux.setIdbehavior(resultset.getInt("idBehavior"));
            newList.add(aux);
        }

        for (Behavior i : oldList) {
            boolean exist = false;
            for (Behavior j : newList) {
                if (i.getBehavior().equals(j.getBehavior())) {
                    exist = true;
                }
            }
            if (!exist) {
                BehaviorJpaController jpaCont = new BehaviorJpaController();
                i.setBehavior(i.getBehavior().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Disposition> saveDisposition(List<Disposition> oldList) throws SQLException {
        List<Disposition> newList = new ArrayList<Disposition>();
        Disposition aux = new Disposition();
        StringBuilder sql = new StringBuilder("select * from disposition where");
        for (Disposition i : oldList) {
            sql.append(" disposition=E'").append(i.getDisposition()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Disposition(); //precisa?
            aux.setDisposition(resultset.getString("Disposition"));
            aux.setIddisposition(resultset.getInt("idDisposition"));
            newList.add(aux);
        }

        for (Disposition i : oldList) {
            boolean exist = false;
            for (Disposition j : newList) {
                if (i.getDisposition().equals(j.getDisposition())) {
                    exist = true;
                }
            }
            if (!exist) {
                DispositionJpaController jpaCont = new DispositionJpaController();
                i.setDisposition(i.getDisposition().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Establishmentmean> saveEstablishmentmean(List<Establishmentmean> oldList) throws SQLException {
        List<Establishmentmean> newList = new ArrayList<Establishmentmean>();
        Establishmentmean aux = new Establishmentmean();
        StringBuilder sql = new StringBuilder("select * from establishmentmean where");
        for (Establishmentmean i : oldList) {
            sql.append(" establishmentmean=E'").append(i.getEstablishmentmean()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Establishmentmean(); //precisa?
            aux.setEstablishmentmean(resultset.getString("Establishmentmean"));
            aux.setIdestablishmentmean(resultset.getInt("idEstablishmentmean"));
            newList.add(aux);
        }

        for (Establishmentmean i : oldList) {
            boolean exist = false;
            for (Establishmentmean j : newList) {
                if (i.getEstablishmentmean().equals(j.getEstablishmentmean())) {
                    exist = true;
                }
            }
            if (!exist) {
                EstablishmentmeanJpaController jpaCont = new EstablishmentmeanJpaController();
                i.setEstablishmentmean(i.getEstablishmentmean().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Lifestage> saveLifestage(List<Lifestage> oldList) throws SQLException {
        List<Lifestage> newList = new ArrayList<Lifestage>();
        Lifestage aux = new Lifestage();
        StringBuilder sql = new StringBuilder("select * from lifestage where");
        for (Lifestage i : oldList) {
            sql.append(" lifestage=E'").append(i.getLifestage()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Lifestage(); //precisa?
            aux.setLifestage(resultset.getString("Lifestage"));
            aux.setIdlifestage(resultset.getInt("idLifestage"));
            newList.add(aux);
        }

        for (Lifestage i : oldList) {
            boolean exist = false;
            for (Lifestage j : newList) {
                if (i.getLifestage().equals(j.getLifestage())) {
                    exist = true;
                }
            }
            if (!exist) {
                LifestageJpaController jpaCont = new LifestageJpaController();
                i.setLifestage(i.getLifestage().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Reproductivecondition> saveReproductivecondition(List<Reproductivecondition> oldList) throws SQLException {
        List<Reproductivecondition> newList = new ArrayList<Reproductivecondition>();
        Reproductivecondition aux = new Reproductivecondition();
        StringBuilder sql = new StringBuilder("select * from reproductivecondition where");
        for (Reproductivecondition i : oldList) {
            sql.append(" reproductivecondition=E'").append(i.getReproductivecondition()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Reproductivecondition(); //precisa?
            aux.setReproductivecondition(resultset.getString("Reproductivecondition"));
            aux.setIdreproductivecondition(resultset.getInt("idReproductivecondition"));
            newList.add(aux);
        }

        for (Reproductivecondition i : oldList) {
            boolean exist = false;
            for (Reproductivecondition j : newList) {
                if (i.getReproductivecondition().equals(j.getReproductivecondition())) {
                    exist = true;
                }
            }
            if (!exist) {
                ReproductiveconditionJpaController jpaCont = new ReproductiveconditionJpaController();
                i.setReproductivecondition(i.getReproductivecondition().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Sex> saveSex(List<Sex> oldList) throws SQLException {
        List<Sex> newList = new ArrayList<Sex>();
        Sex aux = new Sex();
        StringBuilder sql = new StringBuilder("select * from sex where");
        for (Sex i : oldList) {
            sql.append(" sex=E'").append(i.getSex()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Sex(); //precisa?
            aux.setSex(resultset.getString("Sex"));
            aux.setIdsex(resultset.getInt("idSex"));
            newList.add(aux);
        }

        for (Sex i : oldList) {
            boolean exist = false;
            for (Sex j : newList) {
                if (i.getSex().equals(j.getSex())) {
                    exist = true;
                }
            }
            if (!exist) {
                SexJpaController jpaCont = new SexJpaController();
                i.setSex(i.getSex().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Acceptednameusage> saveAcceptednameusage(List<Acceptednameusage> oldList) throws SQLException {
        List<Acceptednameusage> newList = new ArrayList<Acceptednameusage>();
        Acceptednameusage aux = new Acceptednameusage();
        StringBuilder sql = new StringBuilder("select * from acceptednameusage where");
        for (Acceptednameusage i : oldList) {
            sql.append(" acceptednameusage=E'").append(i.getAcceptednameusage()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Acceptednameusage(); //precisa?
            aux.setAcceptednameusage(resultset.getString("Acceptednameusage"));
            aux.setIdacceptednameusage(resultset.getInt("idAcceptednameusage"));
            newList.add(aux);
        }

        for (Acceptednameusage i : oldList) {
            boolean exist = false;
            for (Acceptednameusage j : newList) {
                if (i.getAcceptednameusage().equals(j.getAcceptednameusage())) {
                    exist = true;
                }
            }
            if (!exist) {
                AcceptednameusageJpaController jpaCont = new AcceptednameusageJpaController();
                i.setAcceptednameusage(i.getAcceptednameusage().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Class> saveClass(List<Class> oldList) throws SQLException {
        List<Class> newList = new ArrayList<Class>();
        Class aux = new Class();
        StringBuilder sql = new StringBuilder("select * from Class where");
        for (Class i : oldList) {
            sql.append(" Class=E'").append(i.getClass1()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Class(); //precisa?
            aux.setClass1(resultset.getString("Class"));
            aux.setIdclass(resultset.getInt("idClass"));
            newList.add(aux);
        }

        for (Class i : oldList) {
            boolean exist = false;
            for (Class j : newList) {
                if (i.getClass1().equals(j.getClass1())) {
                    exist = true;
                }
            }
            if (!exist) {
                ClassJpaController jpaCont = new ClassJpaController();
                i.setClass1(i.getClass1().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Family> saveFamily(List<Family> oldList) throws SQLException {
        List<Family> newList = new ArrayList<Family>();
        Family aux = new Family();
        StringBuilder sql = new StringBuilder("select * from Family where");
        for (Family i : oldList) {
            sql.append(" Family=E'").append(i.getFamily()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Family(); //precisa?
            aux.setFamily(resultset.getString("Family"));
            aux.setIdfamily(resultset.getInt("idFamily"));
            newList.add(aux);
        }

        for (Family i : oldList) {
            boolean exist = false;
            for (Family j : newList) {
                if (i.getFamily().equals(j.getFamily())) {
                    exist = true;
                }
            }
            if (!exist) {
                FamilyJpaController jpaCont = new FamilyJpaController();
                i.setFamily(i.getFamily().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Genus> saveGenus(List<Genus> oldList) throws SQLException {
        List<Genus> newList = new ArrayList<Genus>();
        Genus aux = new Genus();
        StringBuilder sql = new StringBuilder("select * from genus where");
        for (Genus i : oldList) {
            sql.append(" genus=E'").append(i.getGenus()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Genus(); //precisa?
            aux.setGenus(resultset.getString("Genus"));
            aux.setIdgenus(resultset.getInt("idGenus"));
            newList.add(aux);
        }

        for (Genus i : oldList) {
            boolean exist = false;
            for (Genus j : newList) {
                if (i.getGenus().equals(j.getGenus())) {
                    exist = true;
                }
            }
            if (!exist) {
                GenusJpaController jpaCont = new GenusJpaController();
                i.setGenus(i.getGenus().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Infraspecificepithet> saveInfraspecificepithet(List<Infraspecificepithet> oldList) throws SQLException {
        List<Infraspecificepithet> newList = new ArrayList<Infraspecificepithet>();
        Infraspecificepithet aux = new Infraspecificepithet();
        StringBuilder sql = new StringBuilder("select * from infraspecificepithet where");
        for (Infraspecificepithet i : oldList) {
            sql.append(" infraspecificepithet=E'").append(i.getInfraspecificepithet()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Infraspecificepithet(); //precisa?
            aux.setInfraspecificepithet(resultset.getString("Infraspecificepithet"));
            aux.setIdinfraspecificepithet(resultset.getInt("idInfraspecificepithet"));
            newList.add(aux);
        }

        for (Infraspecificepithet i : oldList) {
            boolean exist = false;
            for (Infraspecificepithet j : newList) {
                if (i.getInfraspecificepithet().equals(j.getInfraspecificepithet())) {
                    exist = true;
                }
            }
            if (!exist) {
                InfraspecificepithetJpaController jpaCont = new InfraspecificepithetJpaController();
                i.setInfraspecificepithet(i.getInfraspecificepithet().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Kingdom> saveKingdom(List<Kingdom> oldList) throws SQLException {
        List<Kingdom> newList = new ArrayList<Kingdom>();
        Kingdom aux = new Kingdom();
        StringBuilder sql = new StringBuilder("select * from kingdom where");
        for (Kingdom i : oldList) {
            sql.append(" kingdom=E'").append(i.getKingdom()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Kingdom(); //precisa?
            aux.setKingdom(resultset.getString("Kingdom"));
            aux.setIdkingdom(resultset.getInt("idKingdom"));
            newList.add(aux);
        }

        for (Kingdom i : oldList) {
            boolean exist = false;
            for (Kingdom j : newList) {
                if (i.getKingdom().equals(j.getKingdom())) {
                    exist = true;
                }
            }
            if (!exist) {
                KingdomJpaController jpaCont = new KingdomJpaController();
                i.setKingdom(i.getKingdom().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Nameaccordingto> saveNameaccordingto(List<Nameaccordingto> oldList) throws SQLException {
        List<Nameaccordingto> newList = new ArrayList<Nameaccordingto>();
        Nameaccordingto aux = new Nameaccordingto();
        StringBuilder sql = new StringBuilder("select * from nameaccordingto where");
        for (Nameaccordingto i : oldList) {
            sql.append(" nameaccordingto=E'").append(i.getNameaccordingto()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Nameaccordingto(); //precisa?
            aux.setNameaccordingto(resultset.getString("Nameaccordingto"));
            aux.setIdnameaccordingto(resultset.getInt("idNameaccordingto"));
            newList.add(aux);
        }

        for (Nameaccordingto i : oldList) {
            boolean exist = false;
            for (Nameaccordingto j : newList) {
                if (i.getNameaccordingto().equals(j.getNameaccordingto())) {
                    exist = true;
                }
            }
            if (!exist) {
                NameaccordingtoJpaController jpaCont = new NameaccordingtoJpaController();
                i.setNameaccordingto(i.getNameaccordingto().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Namepublishedin> saveNamepublishedin(List<Namepublishedin> oldList) throws SQLException {
        List<Namepublishedin> newList = new ArrayList<Namepublishedin>();
        Namepublishedin aux = new Namepublishedin();
        StringBuilder sql = new StringBuilder("select * from namepublishedin where");
        for (Namepublishedin i : oldList) {
            sql.append(" namepublishedin=E'").append(i.getNamepublishedin()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Namepublishedin(); //precisa?
            aux.setNamepublishedin(resultset.getString("Namepublishedin"));
            aux.setIdnamepublishedin(resultset.getInt("idNamepublishedin"));
            newList.add(aux);
        }

        for (Namepublishedin i : oldList) {
            boolean exist = false;
            for (Namepublishedin j : newList) {
                if (i.getNamepublishedin().equals(j.getNamepublishedin())) {
                    exist = true;
                }
            }
            if (!exist) {
                NamepublishedinJpaController jpaCont = new NamepublishedinJpaController();
                i.setNamepublishedin(i.getNamepublishedin().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Nomenclaturalcode> saveNomenclaturalcode(List<Nomenclaturalcode> oldList) throws SQLException {
        List<Nomenclaturalcode> newList = new ArrayList<Nomenclaturalcode>();
        Nomenclaturalcode aux = new Nomenclaturalcode();
        StringBuilder sql = new StringBuilder("select * from nomenclaturalcode where");
        for (Nomenclaturalcode i : oldList) {
            sql.append(" nomenclaturalcode=E'").append(i.getNomenclaturalcode()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Nomenclaturalcode(); //precisa?
            aux.setNomenclaturalcode(resultset.getString("Nomenclaturalcode"));
            aux.setIdnomenclaturalcode(resultset.getInt("idNomenclaturalcode"));
            newList.add(aux);
        }

        for (Nomenclaturalcode i : oldList) {
            boolean exist = false;
            for (Nomenclaturalcode j : newList) {
                if (i.getNomenclaturalcode().equals(j.getNomenclaturalcode())) {
                    exist = true;
                }
            }
            if (!exist) {
                NomenclaturalcodeJpaController jpaCont = new NomenclaturalcodeJpaController();
                i.setNomenclaturalcode(i.getNomenclaturalcode().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Order1> saveOrder1(List<Order1> oldList) throws SQLException {
        List<Order1> newList = new ArrayList<Order1>();
        Order1 aux = new Order1();
        StringBuilder sql = new StringBuilder("select * from \"order\" where");
        for (Order1 i : oldList) {
            sql.append(" \"order\"=E'").append(i.getOrder()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Order1(); //precisa?
            aux.setOrder(resultset.getString("Order"));
            aux.setIdorder(resultset.getInt("idorder"));
            newList.add(aux);
        }

        for (Order1 i : oldList) {
            boolean exist = false;
            for (Order1 j : newList) {
                if (i.getOrder().equals(j.getOrder())) {
                    exist = true;
                }
            }
            if (!exist) {
                Order1JpaController jpaCont = new Order1JpaController();
                i.setOrder(i.getOrder().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Originalnameusage> saveOriginalnameusage(List<Originalnameusage> oldList) throws SQLException {
        List<Originalnameusage> newList = new ArrayList<Originalnameusage>();
        Originalnameusage aux = new Originalnameusage();
        StringBuilder sql = new StringBuilder("select * from Originalnameusage where");
        for (Originalnameusage i : oldList) {
            sql.append(" Originalnameusage=E'").append(i.getOriginalnameusage()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Originalnameusage(); //precisa?
            aux.setOriginalnameusage(resultset.getString("Originalnameusage"));
            aux.setIdoriginalnameusage(resultset.getInt("idOriginalnameusage"));
            newList.add(aux);
        }

        for (Originalnameusage i : oldList) {
            boolean exist = false;
            for (Originalnameusage j : newList) {
                if (i.getOriginalnameusage().equals(j.getOriginalnameusage())) {
                    exist = true;
                }
            }
            if (!exist) {
                OriginalnameusageJpaController jpaCont = new OriginalnameusageJpaController();
                i.setOriginalnameusage(i.getOriginalnameusage().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Parentnameusage> saveParentnameusage(List<Parentnameusage> oldList) throws SQLException {
        List<Parentnameusage> newList = new ArrayList<Parentnameusage>();
        Parentnameusage aux = new Parentnameusage();
        StringBuilder sql = new StringBuilder("select * from parentnameusage where");
        for (Parentnameusage i : oldList) {
            sql.append(" parentnameusage=E'").append(i.getParentnameusage()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Parentnameusage(); //precisa?
            aux.setParentnameusage(resultset.getString("Parentnameusage"));
            aux.setIdparentnameusage(resultset.getInt("idParentnameusage"));
            newList.add(aux);
        }

        for (Parentnameusage i : oldList) {
            boolean exist = false;
            for (Parentnameusage j : newList) {
                if (i.getParentnameusage().equals(j.getParentnameusage())) {
                    exist = true;
                }
            }
            if (!exist) {
                ParentnameusageJpaController jpaCont = new ParentnameusageJpaController();
                i.setParentnameusage(i.getParentnameusage().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Phylum> savePhylum(List<Phylum> oldList) throws SQLException {
        List<Phylum> newList = new ArrayList<Phylum>();
        Phylum aux = new Phylum();
        StringBuilder sql = new StringBuilder("select * from phylum where");
        for (Phylum i : oldList) {
            sql.append(" phylum=E'").append(i.getPhylum()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Phylum(); //precisa?
            aux.setPhylum(resultset.getString("Phylum"));
            aux.setIdphylum(resultset.getInt("idPhylum"));
            newList.add(aux);
        }

        for (Phylum i : oldList) {
            boolean exist = false;
            for (Phylum j : newList) {
                if (i.getPhylum().equals(j.getPhylum())) {
                    exist = true;
                }
            }
            if (!exist) {
                PhylumJpaController jpaCont = new PhylumJpaController();
                i.setPhylum(i.getPhylum().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Scientificname> saveScientificname(List<Scientificname> oldList) throws SQLException {
        List<Scientificname> newList = new ArrayList<Scientificname>();
        Scientificname aux = new Scientificname();
        StringBuilder sql = new StringBuilder("select * from scientificname where");
        for (Scientificname i : oldList) {
            sql.append(" scientificname=E'").append(i.getScientificname()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Scientificname(); //precisa?
            aux.setScientificname(resultset.getString("Scientificname"));
            aux.setIdscientificname(resultset.getInt("idScientificname"));
            newList.add(aux);
        }

        for (Scientificname i : oldList) {
            boolean exist = false;
            for (Scientificname j : newList) {
                if (i.getScientificname().equals(j.getScientificname())) {
                    exist = true;
                }
            }
            if (!exist) {
                ScientificnameJpaController jpaCont = new ScientificnameJpaController();
                i.setScientificname(i.getScientificname().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Scientificnameauthorship> saveScientificnameauthorship(List<Scientificnameauthorship> oldList) throws SQLException {
        List<Scientificnameauthorship> newList = new ArrayList<Scientificnameauthorship>();
        Scientificnameauthorship aux = new Scientificnameauthorship();
        StringBuilder sql = new StringBuilder("select * from scientificnameauthorship where");
        for (Scientificnameauthorship i : oldList) {
            sql.append(" scientificnameauthorship=E'").append(i.getScientificnameauthorship()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Scientificnameauthorship(); //precisa?
            aux.setScientificnameauthorship(resultset.getString("Scientificnameauthorship"));
            aux.setIdscientificnameauthorship(resultset.getInt("idScientificnameauthorship"));
            newList.add(aux);
        }

        for (Scientificnameauthorship i : oldList) {
            boolean exist = false;
            for (Scientificnameauthorship j : newList) {
                if (i.getScientificnameauthorship().equals(j.getScientificnameauthorship())) {
                    exist = true;
                }
            }
            if (!exist) {
                ScientificnameauthorshipJpaController jpaCont = new ScientificnameauthorshipJpaController();
                i.setScientificnameauthorship(i.getScientificnameauthorship().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        for(Scientificnameauthorship i:newList){

            System.out.println(i.getIdscientificnameauthorship());
        }
        return newList;
    }

    public List<Specificepithet> saveSpecificepithet(List<Specificepithet> oldList) throws SQLException {
        List<Specificepithet> newList = new ArrayList<Specificepithet>();
        Specificepithet aux = new Specificepithet();
        StringBuilder sql = new StringBuilder("select * from specificepithet where");
        for (Specificepithet i : oldList) {
            sql.append(" specificepithet=E'").append(i.getSpecificepithet()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Specificepithet(); //precisa?
            aux.setSpecificepithet(resultset.getString("Specificepithet"));
            aux.setIdspecificepithet(resultset.getInt("idSpecificepithet"));
            newList.add(aux);
        }

        for (Specificepithet i : oldList) {
            boolean exist = false;
            for (Specificepithet j : newList) {
                if (i.getSpecificepithet().equals(j.getSpecificepithet())) {
                    exist = true;
                }
            }
            if (!exist) {
                SpecificepithetJpaController jpaCont = new SpecificepithetJpaController();
                i.setSpecificepithet(i.getSpecificepithet().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Subgenus> saveSubgenus(List<Subgenus> oldList) throws SQLException {
        List<Subgenus> newList = new ArrayList<Subgenus>();
        Subgenus aux = new Subgenus();
        StringBuilder sql = new StringBuilder("select * from subgenus where");
        for (Subgenus i : oldList) {
            sql.append(" subgenus=E'").append(i.getSubgenus()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Subgenus(); //precisa?
            aux.setSubgenus(resultset.getString("Subgenus"));
            aux.setIdsubgenus(resultset.getInt("idSubgenus"));
            newList.add(aux);
        }

        for (Subgenus i : oldList) {
            boolean exist = false;
            for (Subgenus j : newList) {
                if (i.getSubgenus().equals(j.getSubgenus())) {
                    exist = true;
                }
            }
            if (!exist) {
                SubgenusJpaController jpaCont = new SubgenusJpaController();
                i.setSubgenus(i.getSubgenus().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Taxonconcept> saveTaxonconcept(List<Taxonconcept> oldList) throws SQLException {
        List<Taxonconcept> newList = new ArrayList<Taxonconcept>();
        Taxonconcept aux = new Taxonconcept();
        StringBuilder sql = new StringBuilder("select * from taxonconcept where");
        for (Taxonconcept i : oldList) {
            sql.append(" taxonconcept=E'").append(i.getTaxonconcept()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Taxonconcept(); //precisa?
            aux.setTaxonconcept(resultset.getString("Taxonconcept"));
            aux.setIdtaxonconcept(resultset.getInt("idTaxonconcept"));
            newList.add(aux);
        }

        for (Taxonconcept i : oldList) {
            boolean exist = false;
            for (Taxonconcept j : newList) {
                if (i.getTaxonconcept().equals(j.getTaxonconcept())) {
                    exist = true;
                }
            }
            if (!exist) {
                TaxonconceptJpaController jpaCont = new TaxonconceptJpaController();
                i.setTaxonconcept(i.getTaxonconcept().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Taxonomicstatus> saveTaxonomicstatus(List<Taxonomicstatus> oldList) throws SQLException {
        List<Taxonomicstatus> newList = new ArrayList<Taxonomicstatus>();
        Taxonomicstatus aux = new Taxonomicstatus();
        StringBuilder sql = new StringBuilder("select * from taxonomicstatus where");
        for (Taxonomicstatus i : oldList) {
            sql.append(" taxonomicstatus=E'").append(i.getTaxonomicstatus()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Taxonomicstatus(); //precisa?
            aux.setTaxonomicstatus(resultset.getString("Taxonomicstatus"));
            aux.setIdtaxonomicstatus(resultset.getInt("idTaxonomicstatus"));
            newList.add(aux);
        }

        for (Taxonomicstatus i : oldList) {
            boolean exist = false;
            for (Taxonomicstatus j : newList) {
                if (i.getTaxonomicstatus().equals(j.getTaxonomicstatus())) {
                    exist = true;
                }
            }
            if (!exist) {
                TaxonomicstatusJpaController jpaCont = new TaxonomicstatusJpaController();
                i.setTaxonomicstatus(i.getTaxonomicstatus().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Taxonrank> saveTaxonrank(List<Taxonrank> oldList) throws SQLException {
        List<Taxonrank> newList = new ArrayList<Taxonrank>();
        Taxonrank aux = new Taxonrank();
        StringBuilder sql = new StringBuilder("select * from taxonrank where");
        for (Taxonrank i : oldList) {
            sql.append(" taxonrank=E'").append(i.getTaxonrank()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Taxonrank(); //precisa?
            aux.setTaxonrank(resultset.getString("Taxonrank"));
            aux.setIdtaxonrank(resultset.getInt("idTaxonrank"));
            newList.add(aux);
        }

        for (Taxonrank i : oldList) {
            boolean exist = false;
            for (Taxonrank j : newList) {
                if (i.getTaxonrank().equals(j.getTaxonrank())) {
                    exist = true;
                }
            }
            if (!exist) {
                TaxonrankJpaController jpaCont = new TaxonrankJpaController();
                i.setTaxonrank(i.getTaxonrank().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Identificationqualifier> saveIdentificationqualifier(List<Identificationqualifier> oldList) throws SQLException {
        List<Identificationqualifier> newList = new ArrayList<Identificationqualifier>();
        Identificationqualifier aux = new Identificationqualifier();
        StringBuilder sql = new StringBuilder("select * from identificationqualifier where");
        for (Identificationqualifier i : oldList) {
            sql.append(" identificationqualifier=E'").append(i.getIdentificationqualifier()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Identificationqualifier(); //precisa?
            aux.setIdentificationqualifier(resultset.getString("Identificationqualifier"));
            aux.setIdidentificationqualifier(resultset.getInt("idIdentificationqualifier"));
            newList.add(aux);
        }

        for (Identificationqualifier i : oldList) {
            boolean exist = false;
            for (Identificationqualifier j : newList) {
                if (i.getIdentificationqualifier().equals(j.getIdentificationqualifier())) {
                    exist = true;
                }
            }
            if (!exist) {
                IdentificationqualifierJpaController jpaCont = new IdentificationqualifierJpaController();
                i.setIdentificationqualifier(i.getIdentificationqualifier().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Habitat> saveHabitat(List<Habitat> oldList) throws SQLException {
        List<Habitat> newList = new ArrayList<Habitat>();
        Habitat aux = new Habitat();
        StringBuilder sql = new StringBuilder("select * from habitat where");
        for (Habitat i : oldList) {
            sql.append(" habitat=E'").append(i.getHabitat()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Habitat(); //precisa?
            aux.setHabitat(resultset.getString("Habitat"));
            aux.setIdhabitat(resultset.getInt("idHabitat"));
            newList.add(aux);
        }

        for (Habitat i : oldList) {
            boolean exist = false;
            for (Habitat j : newList) {
                if (i.getHabitat().equals(j.getHabitat())) {
                    exist = true;
                }
            }
            if (!exist) {
                HabitatJpaController jpaCont = new HabitatJpaController();
                i.setHabitat(i.getHabitat().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Samplingprotocol> saveSamplingprotocol(List<Samplingprotocol> oldList) throws SQLException {
        List<Samplingprotocol> newList = new ArrayList<Samplingprotocol>();
        Samplingprotocol aux = new Samplingprotocol();
        StringBuilder sql = new StringBuilder("select * from Samplingprotocol where");
        for (Samplingprotocol i : oldList) {
            sql.append(" Samplingprotocol=E'").append(i.getSamplingprotocol()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Samplingprotocol(); //precisa?
            aux.setSamplingprotocol(resultset.getString("Samplingprotocol"));
            aux.setIdsamplingprotocol(resultset.getInt("idSamplingprotocol"));
            newList.add(aux);
        }

        for (Samplingprotocol i : oldList) {
            boolean exist = false;
            for (Samplingprotocol j : newList) {
                if (i.getSamplingprotocol().equals(j.getSamplingprotocol())) {
                    exist = true;
                }
            }
            if (!exist) {
                SamplingprotocolJpaController jpaCont = new SamplingprotocolJpaController();
                i.setSamplingprotocol(i.getSamplingprotocol().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Georeferenceverificationstatus> saveGeoreferenceverificationstatus(List<Georeferenceverificationstatus> oldList) throws SQLException {
        List<Georeferenceverificationstatus> newList = new ArrayList<Georeferenceverificationstatus>();
        Georeferenceverificationstatus aux = new Georeferenceverificationstatus();
        StringBuilder sql = new StringBuilder("select * from georeferenceverificationstatus where");
        for (Georeferenceverificationstatus i : oldList) {
            sql.append(" georeferenceverificationstatus=E'").append(i.getGeoreferenceverificationstatus()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Georeferenceverificationstatus(); //precisa?
            aux.setGeoreferenceverificationstatus(resultset.getString("Georeferenceverificationstatus"));
            aux.setIdgeoreferenceverificationstatus(resultset.getInt("idGeoreferenceverificationstatus"));
            newList.add(aux);
        }

        for (Georeferenceverificationstatus i : oldList) {
            boolean exist = false;
            for (Georeferenceverificationstatus j : newList) {
                if (i.getGeoreferenceverificationstatus().equals(j.getGeoreferenceverificationstatus())) {
                    exist = true;
                }
            }
            if (!exist) {
                GeoreferenceverificationstatusJpaController jpaCont = new GeoreferenceverificationstatusJpaController();
                i.setGeoreferenceverificationstatus(i.getGeoreferenceverificationstatus().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Continent> saveContinent(List<Continent> oldList) throws SQLException {
        List<Continent> newList = new ArrayList<Continent>();
        Continent aux = new Continent();
        StringBuilder sql = new StringBuilder("select * from continent where");
        for (Continent i : oldList) {
            sql.append(" continent=E'").append(i.getContinent()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Continent(); //precisa?
            aux.setContinent(resultset.getString("Continent"));
            aux.setIdcontinent(resultset.getInt("idContinent"));
            newList.add(aux);
        }

        for (Continent i : oldList) {
            boolean exist = false;
            for (Continent j : newList) {
                if (i.getContinent().equals(j.getContinent())) {
                    exist = true;
                }
            }
            if (!exist) {
                ContinentJpaController jpaCont = new ContinentJpaController();
                i.setContinent(i.getContinent().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Country> saveCountry(List<Country> oldList) throws SQLException {
        List<Country> newList = new ArrayList<Country>();
        Country aux = new Country();
        StringBuilder sql = new StringBuilder("select * from country where");
        for (Country i : oldList) {
            sql.append(" country=E'").append(i.getCountry()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Country(); //precisa?
            aux.setCountry(resultset.getString("Country"));
            aux.setIdcountry(resultset.getInt("idCountry"));
            newList.add(aux);
        }

        for (Country i : oldList) {
            boolean exist = false;
            for (Country j : newList) {
                if (i.getCountry().equals(j.getCountry())) {
                    exist = true;
                }
            }
            if (!exist) {
                CountryJpaController jpaCont = new CountryJpaController();
                i.setCountry(i.getCountry().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<County> saveCounty(List<County> oldList) throws SQLException {
        List<County> newList = new ArrayList<County>();
        County aux = new County();
        StringBuilder sql = new StringBuilder("select * from county where");
        for (County i : oldList) {
            sql.append(" county=E'").append(i.getCounty()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new County(); //precisa?
            aux.setCounty(resultset.getString("County"));
            aux.setIdcounty(resultset.getInt("idCounty"));
            newList.add(aux);
        }

        for (County i : oldList) {
            boolean exist = false;
            for (County j : newList) {
                if (i.getCounty().equals(j.getCounty())) {
                    exist = true;
                }
            }
            if (!exist) {
                CountyJpaController jpaCont = new CountyJpaController();
                i.setCounty(i.getCounty().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Island> saveIsland(List<Island> oldList) throws SQLException {
        List<Island> newList = new ArrayList<Island>();
        Island aux = new Island();
        StringBuilder sql = new StringBuilder("select * from island where");
        for (Island i : oldList) {
            sql.append(" island=E'").append(i.getIsland()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Island(); //precisa?
            aux.setIsland(resultset.getString("Island"));
            aux.setIdisland(resultset.getInt("idIsland"));
            newList.add(aux);
        }

        for (Island i : oldList) {
            boolean exist = false;
            for (Island j : newList) {
                if (i.getIsland().equals(j.getIsland())) {
                    exist = true;
                }
            }
            if (!exist) {
                IslandJpaController jpaCont = new IslandJpaController();
                i.setIsland(i.getIsland().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Islandgroup> saveIslandgroup(List<Islandgroup> oldList) throws SQLException {
        List<Islandgroup> newList = new ArrayList<Islandgroup>();
        Islandgroup aux = new Islandgroup();
        StringBuilder sql = new StringBuilder("select * from islandgroup where");
        for (Islandgroup i : oldList) {
            sql.append(" islandgroup=E'").append(i.getIslandgroup()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Islandgroup(); //precisa?
            aux.setIslandgroup(resultset.getString("Islandgroup"));
            aux.setIdislandgroup(resultset.getInt("idIslandgroup"));
            newList.add(aux);
        }

        for (Islandgroup i : oldList) {
            boolean exist = false;
            for (Islandgroup j : newList) {
                if (i.getIslandgroup().equals(j.getIslandgroup())) {
                    exist = true;
                }
            }
            if (!exist) {
                IslandgroupJpaController jpaCont = new IslandgroupJpaController();
                i.setIslandgroup(i.getIslandgroup().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Locality> saveLocality(List<Locality> oldList) throws SQLException {
        List<Locality> newList = new ArrayList<Locality>();
        Locality aux = new Locality();
        StringBuilder sql = new StringBuilder("select * from locality where");
        for (Locality i : oldList) {
            sql.append(" locality=E'").append(i.getLocality()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Locality(); //precisa?
            aux.setLocality(resultset.getString("Locality"));
            aux.setIdlocality(resultset.getInt("idLocality"));
            newList.add(aux);
        }

        for (Locality i : oldList) {
            boolean exist = false;
            for (Locality j : newList) {
                if (i.getLocality().equals(j.getLocality())) {
                    exist = true;
                }
            }
            if (!exist) {
                LocalityJpaController jpaCont = new LocalityJpaController();
                i.setLocality(i.getLocality().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Municipality> saveMunicipality(List<Municipality> oldList) throws SQLException {
        List<Municipality> newList = new ArrayList<Municipality>();
        Municipality aux = new Municipality();
        StringBuilder sql = new StringBuilder("select * from municipality where");
        for (Municipality i : oldList) {
            sql.append(" municipality=E'").append(i.getMunicipality()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Municipality(); //precisa?
            aux.setMunicipality(resultset.getString("Municipality"));
            aux.setIdmunicipality(resultset.getInt("idMunicipality"));
            newList.add(aux);
        }

        for (Municipality i : oldList) {
            boolean exist = false;
            for (Municipality j : newList) {
                if (i.getMunicipality().equals(j.getMunicipality())) {
                    exist = true;
                }
            }
            if (!exist) {
                MunicipalityJpaController jpaCont = new MunicipalityJpaController();
                i.setMunicipality(i.getMunicipality().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Stateprovince> saveStateprovince(List<Stateprovince> oldList) throws SQLException {
        List<Stateprovince> newList = new ArrayList<Stateprovince>();
        Stateprovince aux = new Stateprovince();
        StringBuilder sql = new StringBuilder("select * from stateprovince where");
        for (Stateprovince i : oldList) {
            sql.append(" stateprovince=E'").append(i.getStateprovince()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Stateprovince(); //precisa?
            aux.setStateprovince(resultset.getString("Stateprovince"));
            aux.setIdstateprovince(resultset.getInt("idStateprovince"));
            newList.add(aux);
        }

        for (Stateprovince i : oldList) {
            boolean exist = false;
            for (Stateprovince j : newList) {
                if (i.getStateprovince().equals(j.getStateprovince())) {
                    exist = true;
                }
            }
            if (!exist) {
                StateprovinceJpaController jpaCont = new StateprovinceJpaController();
                i.setStateprovince(i.getStateprovince().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Waterbody> saveWaterbody(List<Waterbody> oldList) throws SQLException {
        List<Waterbody> newList = new ArrayList<Waterbody>();
        Waterbody aux = new Waterbody();
        StringBuilder sql = new StringBuilder("select * from waterbody where");
        for (Waterbody i : oldList) {
            sql.append(" waterbody=E'").append(i.getWaterbody()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Waterbody(); //precisa?
            aux.setWaterbody(resultset.getString("Waterbody"));
            aux.setIdwaterbody(resultset.getInt("idWaterbody"));
            newList.add(aux);
        }

        for (Waterbody i : oldList) {
            boolean exist = false;
            for (Waterbody j : newList) {
                if (i.getWaterbody().equals(j.getWaterbody())) {
                    exist = true;
                }
            }
            if (!exist) {
                WaterbodyJpaController jpaCont = new WaterbodyJpaController();
                i.setWaterbody(i.getWaterbody().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Dynamicproperty> saveDynamicpropertyNN(List<Dynamicproperty> oldList) throws SQLException {
        List<Dynamicproperty> newList = new ArrayList<Dynamicproperty>();
        Dynamicproperty aux = new Dynamicproperty();
        StringBuilder sql = new StringBuilder("select * from Dynamicproperty where");
        for (Dynamicproperty i : oldList) {
            sql.append(" Dynamicproperty=E'").append(i.getDynamicproperty()).append("' OR ");
        }

        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Dynamicproperty(); //precisa?
            aux.setDynamicproperty(resultset.getString("Dynamicproperty"));
            aux.setIddynamicproperty(resultset.getInt("idDynamicproperty"));
            newList.add(aux);
        }

        for (Dynamicproperty i : oldList) {
            boolean exist = false;
            for (Dynamicproperty j : newList) {
                if (i.getDynamicproperty().equals(j.getDynamicproperty())) {
                    exist = true;
                }
            }
            if (!exist) {
                DynamicpropertyJpaController jpaCont = new DynamicpropertyJpaController();
                i.setDynamicproperty(i.getDynamicproperty().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Georeferencesource> saveGeoreferencesourceNN(List<Georeferencesource> oldList) throws SQLException {
        List<Georeferencesource> newList = new ArrayList<Georeferencesource>();
        Georeferencesource aux = new Georeferencesource();
        StringBuilder sql = new StringBuilder("select * from Georeferencesource where");
        for (Georeferencesource i : oldList) {
            sql.append(" Georeferencesource=E'").append(i.getGeoreferencesource()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Georeferencesource(); //precisa?
            aux.setGeoreferencesource(resultset.getString("Georeferencesource"));
            aux.setIdgeoreferencesource(resultset.getInt("idGeoreferencesource"));
            newList.add(aux);
        }

        for (Georeferencesource i : oldList) {
            boolean exist = false;
            for (Georeferencesource j : newList) {
                if (i.getGeoreferencesource().equals(j.getGeoreferencesource())) {
                    exist = true;
                }
            }
            if (!exist) {
                GeoreferencesourceJpaController jpaCont = new GeoreferencesourceJpaController();
                i.setGeoreferencesource(i.getGeoreferencesource().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Associatedsequence> saveAssociatedsequenceNN(List<Associatedsequence> oldList) throws SQLException {
        List<Associatedsequence> newList = new ArrayList<Associatedsequence>();
        Associatedsequence aux = new Associatedsequence();
        StringBuilder sql = new StringBuilder("select * from Associatedsequence where");
        for (Associatedsequence i : oldList) {
            sql.append(" Associatedsequence=E'").append(i.getAssociatedsequence()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Associatedsequence(); //precisa?
            aux.setAssociatedsequence(resultset.getString("Associatedsequence"));
            aux.setIdassociatedsequence(resultset.getInt("idAssociatedsequence"));
            newList.add(aux);
        }

        for (Associatedsequence i : oldList) {
            boolean exist = false;
            for (Associatedsequence j : newList) {
                if (i.getAssociatedsequence().equals(j.getAssociatedsequence())) {
                    exist = true;
                }
            }
            if (!exist) {
                AssociatedsequenceJpaController jpaCont = new AssociatedsequenceJpaController();
                i.setAssociatedsequence(i.getAssociatedsequence().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Individual> saveIndividualNN(List<Individual> oldList) throws SQLException {
        List<Individual> newList = new ArrayList<Individual>();
        Individual aux = new Individual();
        StringBuilder sql = new StringBuilder("select * from Individual where");
        for (Individual i : oldList) {
            sql.append(" Individual=E'").append(i.getIndividual()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Individual(); //precisa?
            aux.setIndividual(resultset.getString("Individual"));
            aux.setIdindividual(resultset.getInt("idIndividual"));
            newList.add(aux);
        }

        for (Individual i : oldList) {
            boolean exist = false;
            for (Individual j : newList) {
                if (i.getIndividual().equals(j.getIndividual())) {
                    exist = true;
                }
            }
            if (!exist) {
                IndividualJpaController jpaCont = new IndividualJpaController();
                i.setIndividual(i.getIndividual().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Preparation> savePreparationNN(List<Preparation> oldList) throws SQLException {
        List<Preparation> newList = new ArrayList<Preparation>();
        Preparation aux = new Preparation();
        StringBuilder sql = new StringBuilder("select * from Preparation where");
        for (Preparation i : oldList) {
            sql.append(" Preparation=E'").append(i.getPreparation()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Preparation(); //precisa?
            aux.setPreparation(resultset.getString("Preparation"));
            aux.setIdpreparation(resultset.getInt("idPreparation"));
            newList.add(aux);
        }

        for (Preparation i : oldList) {
            boolean exist = false;
            for (Preparation j : newList) {
                if (i.getPreparation().equals(j.getPreparation())) {
                    exist = true;
                }
            }
            if (!exist) {
                PreparationJpaController jpaCont = new PreparationJpaController();
                i.setPreparation(i.getPreparation().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Recordedby> saveRecordedbyNN(List<Recordedby> oldList) throws SQLException {
        List<Recordedby> newList = new ArrayList<Recordedby>();
        Recordedby aux = new Recordedby();
        StringBuilder sql = new StringBuilder("select * from Recordedby where");
        for (Recordedby i : oldList) {
            sql.append(" Recordedby=E'").append(i.getRecordedby()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Recordedby(); //precisa?
            aux.setRecordedby(resultset.getString("Recordedby"));
            aux.setIdrecordedby(resultset.getInt("idRecordedby"));
            newList.add(aux);
        }

        for (Recordedby i : oldList) {
            boolean exist = false;
            for (Recordedby j : newList) {
                if (i.getRecordedby().equals(j.getRecordedby())) {
                    exist = true;
                }
            }
            if (!exist) {
                RecordedbyJpaController jpaCont = new RecordedbyJpaController();
                i.setRecordedby(i.getRecordedby().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Identifiedby> saveIdentifiedbyNN(List<Identifiedby> oldList) throws SQLException {
        List<Identifiedby> newList = new ArrayList<Identifiedby>();
        Identifiedby aux = new Identifiedby();
        StringBuilder sql = new StringBuilder("select * from Identifiedby where");
        for (Identifiedby i : oldList) {
            sql.append(" Identifiedby=E'").append(i.getIdentifiedby()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Identifiedby(); //precisa?
            aux.setIdentifiedby(resultset.getString("Identifiedby"));
            aux.setIdidentifiedby(resultset.getInt("idIdentifiedby"));
            newList.add(aux);
        }

        for (Identifiedby i : oldList) {
            boolean exist = false;
            for (Identifiedby j : newList) {
                if (i.getIdentifiedby().equals(j.getIdentifiedby())) {
                    exist = true;
                }
            }
            if (!exist) {
                IdentifiedbyJpaController jpaCont = new IdentifiedbyJpaController();
                i.setIdentifiedby(i.getIdentifiedby().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Typestatus> saveTypestatusNN(List<Typestatus> oldList) throws SQLException {
        List<Typestatus> newList = new ArrayList<Typestatus>();
        Typestatus aux = new Typestatus();
        StringBuilder sql = new StringBuilder("select * from Typestatus where");
        for (Typestatus i : oldList) {
            sql.append(" Typestatus=E'").append(i.getTypestatus()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Typestatus(); //precisa?
            aux.setTypestatus(resultset.getString("Typestatus"));
            aux.setIdtypestatus(resultset.getInt("idTypestatus"));
            newList.add(aux);
        }

        for (Typestatus i : oldList) {
            boolean exist = false;
            for (Typestatus j : newList) {
                if (i.getTypestatus().equals(j.getTypestatus())) {
                    exist = true;
                }
            }
            if (!exist) {
                TypestatusJpaController jpaCont = new TypestatusJpaController();
                i.setTypestatus(i.getTypestatus().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }

    public List<Georeferencedby> saveGeoreferencedbyNN(List<Georeferencedby> oldList) throws SQLException {
        List<Georeferencedby> newList = new ArrayList<Georeferencedby>();
        Georeferencedby aux = new Georeferencedby();
        StringBuilder sql = new StringBuilder("select * from Georeferencedby where");
        for (Georeferencedby i : oldList) {
            sql.append(" Georeferencedby=E'").append(i.getGeoreferencedby()).append("' OR ");
        }
        Statement stm = conn.createStatement();
        ResultSet resultset = stm.executeQuery(sql.toString().replaceAll(" OR $", ""));
        while (resultset.next()) {
            aux = new Georeferencedby(); //precisa?
            aux.setGeoreferencedby(resultset.getString("Georeferencedby"));
            aux.setIdgeoreferencedby(resultset.getInt("idGeoreferencedby"));
            newList.add(aux);
        }

        for (Georeferencedby i : oldList) {
            boolean exist = false;
            for (Georeferencedby j : newList) {
                if (i.getGeoreferencedby().equals(j.getGeoreferencedby())) {
                    exist = true;
                }
            }
            if (!exist) {
                GeoreferencedbyJpaController jpaCont = new GeoreferencedbyJpaController();
                i.setGeoreferencedby(i.getGeoreferencedby().replaceAll("\\\\\\\\", "\\\\").replaceAll("''", "'"));
                i = jpaCont.create(i);
                newList.add(i);
            }
        }
        return newList;
    }
}
